package com.corpdata.app.project.service.impl;

import java.util.HashMap;
import java.util.Map;
import com.corpdata.app.project.service.ProjectTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.corpdata.app.project.dao.ProjectInfoMapper;
import com.corpdata.app.project.entity.ProjectInfo;
import com.corpdata.app.project.service.ProjectInfoService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.common.upload.entity.SysAttachment;
import com.corpdata.common.upload.service.SysAttachmentService;
import com.corpdata.common.utils.CorpdataUtil;
import com.corpdata.core.base.AbstractBaseService;
import com.corpdata.system.security.shiro.util.UserUtil;

/**
 * 分店表
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-08 15:23:00
 */
@Service
@Transactional
public class ProjectInfoServiceImpl extends AbstractBaseService<ProjectInfo> implements ProjectInfoService {
	
	@Autowired
	ProjectTeamService projectTeamService;
	
	@Autowired
	ProjectInfoMapper projectInfoMapper;
	
	@Autowired
	private SysAttachmentService sysAttachmentService;
	
	
	public Result insert(ProjectInfo record,String teamUserids,String teamUserid,String fileId){
		if(teamUserids!=null){
			projectTeamService.insert(record.getId(), teamUserids, "2", 0);
		}
		if(teamUserid!=null){
			projectTeamService.insert(record.getId(), teamUserid, "1", 1);
		}
		sysAttachmentService.updateDel(fileId,record.getId());
		return super.save(record);
	}
	
	public String findByPage(DataGridRequestDTO dgRequest){
		Map<String,Object> params=null;
		if(dgRequest.getParams()!=null){
			params=dgRequest.getParams();
		}else{
			params=new HashMap<String,Object>();
		}
		params.put("userId", UserUtil.getCurrentOrgUser().getId());
		dgRequest.setParams(params);
		return super.findByPage(dgRequest);
	}
	
	public Result update(ProjectInfo record,String fileId,String sysAttachmentPortraitId){
		sysAttachmentService.updateDel(fileId,record.getId());
		SysAttachment sa=new SysAttachment();
		sa.setId(sysAttachmentPortraitId);
		record.setAttachment(sa);
		return super.update(record);
	}
}
